#include "Profile.h"
#include <fstream>

Profile::Profile(const char *szFile, int iLine, const char *szFunc)
{
	static bool created = false;
	static long long id = 0;
	m_prof = new Prof(szFile, iLine, szFunc, id++);
	
	if (MODE == "file") {
		ofstream fout;
		if (created)
			fout.open(OUT, ofstream::app);
		else {
			fout.open(OUT);
			created = true;
		}
		fout << m_prof->file << '\n';
		fout << m_prof->line << '\n';
		fout << m_prof->func << '\n';
		fout << m_prof->log << '\n';
		fout << m_prof->msec << '\n';

        //fout.write((char*) m_prof, sizeof Prof);
        fout.close();
	} else 
		if (MODE == "cout") {
		cout << szFile <<", " << iLine << ", " << szFunc << ", ";
		cout << "Started! " /*<< m_prof->log */<< '\n';
	}
}


Profile::~Profile(void)
{
	if (MODE == "file") {
		ofstream fout;
		fout.open(OUT, ofstream::app);
		fout << m_prof->file << '\n';
		fout << m_prof->line << '\n';
		fout << m_prof->func << '\n';
		fout << m_prof->log << '\n';
		fout << float(clock() - m_prof->msec)/CLOCKS_PER_SEC << '\n';
        fout.close();
	} else 
		if (MODE == "cout") {
		cout << m_prof->file <<", " << m_prof->line << ", " << m_prof->func << ", ";
		cout << "Finished! " << float(clock() - m_prof->msec)/CLOCKS_PER_SEC << '\n';
	}
	delete m_prof;
}
